package Session;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
/*
* Session
* 把数据保存在服务器端
*   request.getSession()
*       根据request请求对象中的Cookie中的JSESSIONID的值，来获取对应的Session对象，
*             没有则创建，并在响应时将JSESSIONID的值写入到Cookie中
*   session.setAttribute("key","value");    创建键值对属性值，这是Session保存数据的方式
*   session.getAttribute("key");            获取键值对属性值
*   session.removeAttribute("key");         删除键值对属性值
*   session.invalidate();                   销毁Session对象
*
* */
@WebServlet(value = "/SessionDemo/demo01")
public class SessionDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        session.setAttribute("id","456");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
